<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->


    <link href="__ADMIN_TMPL__/public/assets/themes/{:cmf_get_admin_style()}/bootstrap.min.css" rel="stylesheet">
    <link href="__ADMIN_TMPL__/public/assets/simpleboot3/css/simplebootadmin.css" rel="stylesheet">
    <link href="__ADMIN_TMPL__/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        form .input-order {
            margin-bottom: 0px;
            padding: 0 2px;
            width: 42px;
            font-size: 12px;
        }

        form .input-order:focus {
            outline: none;
        }

        .table-actions {
            margin-top: 5px;
            margin-bottom: 5px;
            padding: 0px;
        }

        .table-list {
            margin-bottom: 0px;
        }

        .form-required {
            color: red;
        }
    </style>
    <script type="text/javascript">
        //全局变量
        var GV = {
            ROOT: "__ROOT__/",
            WEB_ROOT: "__WEB_ROOT__/",
            JS_ROOT: "static/js/",
            APP: '{$Request.module}'/*当前应用名*/
        };
    </script>
    <script src="__ADMIN_TMPL__/public/assets/js/jquery-1.10.2.min.js"></script>
    <script src="__STATIC__/js/wind.js"></script>
    <script src="__ADMIN_TMPL__/public/assets/js/bootstrap.min.js"></script>
    <script>
        Wind.css('artDialog');
        Wind.css('layer');
        $(function () {
            $("[data-toggle='tooltip']").tooltip({
                container:'body',
                html:true,
            });
            $("li.dropdown").hover(function () {
                $(this).addClass("open");
            }, function () {
                $(this).removeClass("open");
            });
        });
    </script>
    <if condition="APP_DEBUG">
        <style>
            #think_page_trace_open {
                z-index: 9999;
            }
        </style>
    </if>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:cmf_plugin_url('QbtMemberForMall://AdminIndex/index')}">会员列表</a></li>
        <li class="active"><a href="{:cmf_plugin_url('QbtMemberForMall://AdminIndex/add')}">添加会员</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20"
          action="{:cmf_plugin_url('QbtMemberForMall://AdminIndex/add')}" onsubmit="return checkForm()">
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>用户名</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" name="user_name" value="" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>手机</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" name="mobile_phone" value="" required>
                <div class="ts" style="color:#f00;font-size: 12px;height: 20px;line-height: 20px;display: none;">手机号码不合法</div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">性别</label>
            <div class="col-md-6 col-sm-10">
                <label class="radio-inline">
                    <input type="radio" name="sex" value="1" checked>男
                </label>
                <label class="radio-inline">
                    <input type="radio" name="sex" value="0">女
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">省市区</label>
            <div class="col-md-2 col-sm-3">
                <select name="a1" class="form-control" onchange="selajax(this,1)">
                    <option value="0">请选择</option>
                    <foreach name="list" key="k" item="vo">
                        <option value="{$vo.name}">{$vo.name}</option>
                    </foreach>
                </select>
                <div class="ts1" style="color:#f00;font-size: 12px;height: 20px;line-height: 20px;display: none;">请选择省市区</div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>详细地址</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" name="addr" value="" required>
            </div>
        </div>
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-primary js-ajax-submit">{:lang("SAVE")}</button>
        </div>
    </form>
</div>
<script>
    function selajax(a,b){
        var name = $(a).val();
        $(a).parent().nextAll().remove();
        if (name==0){
            return;
        }
        var str='';
        $.ajax({
            type: "GET",
            url: "{:cmf_plugin_url('QbtMemberForMall://AdminIndex/selajax')}",
            data: {name:name},
            dataType: "json",
            success: function(data){
                b++;
                if (data.length==0) {
                    return;
                }
                str += '<div class="col-md-2 col-sm-3">\n' +
                    '                <select name="a'+b+'" class="form-control" onchange="selajax(this,'+b+')"><option value="0">请选择</option>';
                for(x in data){
                    str += '<option value="'+data[x]['name']+'">'+data[x]['name']+'</option>';
                }
                str += ' </select>\n' +
                    '            </div>';
                $(a).parent().after(str);
            }
        });
    }

    function checkForm() {
        var arr = [];
        var phone = $("[name='mobile_phone']").val();
        var pattern = /^1[34578]\d{9}$/;
        $("select").each(function(){
            if ($(this).val()==0) {
                arr.push($(this).val());
            }
        });
        console.log(arr);
        console.log($.inArray('0', arr));
        if (!pattern.test(phone)) {
            $('.ts').css('display','block');
            return false;
        }else if ($.inArray('0', arr)>= 0) {
            $('.ts1').css('display','block');
            return false;
        }else{
            $('.ts').css('display','none');
            $('.ts1').css('display','none');
            return true;
        }
    }
</script>
</body>
</html>